﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - TaskAdjust" 
*/ 

component 
	displayname="public.service.db.senate.sequence.TaskAdjust" 
	output=false 
	accessors=true 
	{

	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}

	/**
	* @hint "自定义主键规则"
	*/
	public string function getNextID() output=false {
		
		var nextID = year(now()) & numberFormat(1, "0_____");
		
		sql = "	SELECT sign_id FROM t_task_adjust WHERE sign_id LIKE :condition ORDER BY sign_id DESC";
		queryObj = new Query( datasource=application.dnsMaster, maxRows=1 );
		queryObj.addParam( name="condition", value=year(now()) & "______", cfsqltype="cf_sql_char" );	
		var rs_check = queryObj.execute( sql=sql ).getResult();
		
		/* 
			主键生成规则 
			
			4位年份 + 6位流水号
			
		*/
		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = year(now()) & numberFormat((right(rs_check.sign_id, 6) + 1), "0_____");
			
		}

		return nextID;
	}

}

</cfscript>